<template>
  <a-form layout="inline">
    <a-form-item label="产线">
      <a-select v-model="form.line" class="slect-width">
        <a-select-option v-for="(item,index) in selectList.lines" :key="'line-sel-'+index" :value="item.id">{{item.name}}</a-select-option>
      </a-select>
    </a-form-item>
    <a-form-item>
      <a-button type="primary" @click.stop="onSearch">查询</a-button>
    </a-form-item>
  </a-form>
</template>

<script>
import { GetProductionLines } from '@/api/modular/main/StationViewManage'
export default {
  name:'stationViewSearchCompontent',
  emits:['update:loading','search'],
  data(){
    return {
      loading:{
        type:Boolean,
        default:false
      },
      form:{
        line :null
      },
      selectList:{
        lines:[]
      }
    }
  },
  methods:{
    init(callback){
      this.getSelectListLines((f)=>{
        if (f) {
          callback && callback(true,this.form.line)
        } else {
          callback && callback(false)
        }
      })
    },
    getSelectListLines(callback){
      GetProductionLines().then((d)=>{
        this.selectList.lines = d.data || [];
        if (this.selectList.lines.length>0) {
          this.form.line = this.selectList.lines[0].id
          callback && callback(true)
        } else {
          callback && callback(false)
        }
      }).catch(()=>{
        callback && callback(false)
      })
    },
    onSearch(){
      if (!this.form.line) {
        this.$error({
          title: '系统提示',
          content: '请选择产线！',
        });
        return false;
      }
      this.$emit('search',this.form.line)
    }
  }
}
</script>

<style lang="less" scoped>
.slect-width{
  width:180px
}
</style>